package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.StashDetail;
import com.qf.entity.StashRecords;
import com.qf.service.DetailService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 业精于勤,荒于嬉 ---
 *
 * @author Song
 * @date 2024/7/25
 * @desc First
 */
@RestController
@RequestMapping("/stash/detail")
public class DetailController {

    @Autowired
    private DetailService service;

    /**
     * 查询全部计量单位
     * 分页和模糊搜索
     */
    @GetMapping("/list")
    public R findAll(@RequestParam HashMap<String,String> map){
        int pageNum = Integer.parseInt(map.get("pageNum"));
        int pageSize = Integer.parseInt(map.get("pageSize"));
        PageHelper.startPage(pageNum,pageSize);

        List<StashDetail> list = service.findAll(map);
        PageInfo<StashDetail> info = new PageInfo<>(list);
        System.out.println(info);
        return R.ok(info);
    }
    /**
     * 根据ID删除
     */
    @GetMapping("/del")
    public R delById(int id){
        boolean isOk = service.deleteById(id);
        return R.ok();
    }
    /**
     * 下拉框
     */
    @GetMapping("/find3")
    public R find3() {
        List<String> list =  service.find3();
        return R.ok(list);
    }
    /**
     * 修改计量单位
     */
    @PostMapping("/edit")
    public R edit(@RequestBody HashMap<String,String> map){
        boolean ok = service.edit(map);
        return R.ok(ok);
    }


}
